;; Maciek's Emacs configuration
;;
;; Available on: http://code.google.com/p/maciek-emacs/

;; TODO - auto-compile all the init files
;; TODO - migrate ~/.emacs wrapper to this file here;
;;        rely on ~/.emacs.d/init.el loading

;; ----- package management
(load-file "~/emacs/init-package-load.el")

;; ----- initial settings

;; The latter doesn't really work; read the docs for the var.  Only
;; way I have succeeded in turning the echo area message off is using
;; customization.
;; -- already in init-looks.el
;; (setq inhibit-startup-screen t)
;; (setq inhibit-startup-echo-area-message "maciek")

;; Keep customizations separate.
;; Load them before the other scripts, in case we rely
;; on some of them (e.g., which themes are safe to load).
(setq custom-file "~/.emacs.d/customizations.el")
(load custom-file 'noerror)

(add-to-list 'load-path (expand-file-name "~/emacs"))
(add-to-list 'load-path (expand-file-name "~/emacs/site-lisp"))
(add-to-list 'load-path (expand-file-name "/usr/local/go/misc/emacs/"))

;; helper function
;; TODO surely elisp has this already?
;; (NOTE: do NOT want ignore if file exists BUT there was another error reading it)
(defun load-if-exists (filepath)
  "Load the file if it exists."
  (if (file-exists-p filepath)
      (load-file filepath)))

;; ----- load personal initializations
(load-file "~/emacs/init-looks.el")
(load-file "~/emacs/init-settings.el")
(load-file "~/emacs/init-keys.el")
(load-file "~/emacs/init-misc.el")
(load-file "~/emacs/init-go.el")

;; TODO: make this conditional on existence
(load-if-exists "~/emacs/init-secret.el")

;; ----- load package-specific initializations
;; TODO - merge into init-packages.el, once I figure out section folding
;; TODO - consider using use-package:
;;        http://ericjmritz.name/2013/11/25/simplify-emacs-configuration-with-use-package/
(require 'diminish)
(load-file "~/emacs/init-autopair.el")
(load-file "~/emacs/init-deft.el")
(load-file "~/emacs/init-dired.el")
(load-file "~/emacs/init-fic.el")
(load-file "~/emacs/init-helm.el")
(load-file "~/emacs/init-org.el")

;; These are made obsolete by 'helm'.
;(load-file "~/emacs/init-ido.el")
;(load-file "~/emacs/init-smex.el")

;; OS-specific initialization
(cond
 ((eq system-type 'windows-nt)
  (load-file "~/emacs/init-mswin.el"))
 ((eq system-type 'gnu/linux)  ;; Linux
  (load-file "~/emacs/init-linux.el"))
 ((eq system-type 'darwin)
  (load-file "~/emacs/init-osx.el"))
)

;; various fixes for broken features
(load-file "~/emacs/init-fixes.el")

;; personal key bindings
(global-set-key "\C-cb" 'bury-buffer)
(global-set-key (kbd "M-/") 'hippie-expand)
;; ----- end matter

;; allows 'emacsclient' to connect to already running Emacs
(require 'server)
(if (not (server-running-p))
    (server-start))

;; Ask for confirmation before quitting Emacs
(add-hook 'kill-emacs-query-functions
          (lambda () (y-or-n-p "Do you really want to exit Emacs? "))
          'append)

;; Disable certain warnings about dangerous commands.
;; ObMeme: I too like to live dangerously...
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
